package com.dykj.fireFighting.server.base.fireGroup.service.impl;


import com.dykj.fireFighting.api.base.bigdata.device.entity.Device;
import com.dykj.fireFighting.api.base.bigdata.device.service.IDeviceService;
import com.dykj.fireFighting.api.base.enterprise.entity.Enterprise;
import com.dykj.fireFighting.api.base.enterprise.service.IEnterpriseService;
import com.dykj.fireFighting.api.base.fireGroup.dto.FireGroupAndDevDto;
import com.dykj.fireFighting.api.base.fireGroup.entity.FireGroupAndDev;
import com.dykj.fireFighting.api.base.fireGroup.service.IFireGroupAndDevService;
import com.dykj.fireFighting.common.core.service.impl.BaseServiceImpl;
import com.dykj.fireFighting.common.core.utils.UUIDUtils;
import com.dykj.fireFighting.server.base.bigdata.mapper.DeviceMapper;
import com.dykj.fireFighting.server.base.fireGroup.mapper.FireGroupAndDevMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;


import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 消防巡更-消防群组
 *
 * @Author JacksonTu
 * @Date  2021-06-28 14:54:24
 */
@Slf4j
@DubboService
@Transactional(rollbackFor = Exception.class)
public class FireGroupAndDevServiceImpl extends BaseServiceImpl<FireGroupAndDevMapper, FireGroupAndDev> implements IFireGroupAndDevService {
    @Autowired
    private IEnterpriseService enterpriseService;
    @Autowired
    private DeviceMapper deviceMapper;
    @Override
    public List<FireGroupAndDev> getList(FireGroupAndDevDto commonDto,int enterpriseType,String enterpriseId) {
        Map<String, Object> params=new HashMap<>();
        List<String> unitIds= new ArrayList();
        if(enterpriseType==0){   //社会单位
            unitIds.add(commonDto.getUnitId());
        }else{                  //维保单位
            HashMap<String, Object> params1 = new HashMap<>(16);
            params1.put("weibaoUnit",enterpriseId);
            List<Enterprise> list=enterpriseService.querySocialUnits(params1);
            for (Enterprise e: list) {
                unitIds.add(e.getId().toString());
            }
        }
        params.put("unitIds",unitIds);
        List<FireGroupAndDev> list=this.baseMapper.getList(params);
        for (int i = 0; i < list.size(); i++) {
            List<Device> devList=deviceMapper.getDeviceByGroupId(list.get(i).getId());
            list.get(i).setDevList(devList);
        }
        return list;
    }
}
